/**
 *@note Copyright 2012-2022 CETHIK All Rights Reserved.
 *@brief 代价地图层文件。
 *@author tuyinan
 *@data 2022-04-xx
 */
#ifndef COSTMAP_2D_COSTMAP_LAYER_H_
#define COSTMAP_2D_COSTMAP_LAYER_H_
#include <costmap_2d/layer.h>
#include <costmap_2d/layered_costmap.h>
//#include<costmap_2d/costmap_2d.h>

namespace costmap_2d {
/**
 *@brief 代价地图层类，继承层类和costmap2d类
 *@author tuyinan
 *@version 2022-04-xx
 */
class CostmapLayer : public Layer, public Costmap2D {
 public:
  /**
   *@brief 构造函数
   *@param 无
   *@return void
   *@author: tuyinan
   *@version: 2022-04-xx
   */
  CostmapLayer()
      : has_extra_bounds_(false),
        extra_min_x_(1e6),
        extra_max_x_(-1e6),
        extra_min_y_(1e6),
        extra_max_y_(-1e6) {}
  /**
   *@brief 地图匹配大小
   *@param 无
   *@return void
   *@author: tuyinan
   *@version: 2022-04-xx
   */
  virtual void matchSize();
  /**
   *@brief 将区域清空
   *@param int start_x 开始点的x
   *@param int start_y 开始点的y
   *@param int end_x 开始点的x
   *@param int end_y 开始点的y
   *@return void
   *@author: tuyinan
   *@version: 2022-04-xx
   */
  virtual void clearArea(int start_x, int start_y, int end_x, int end_y);
  /**
   *@brief 外部对代价地图操作时记录修改的区域
   *@param double mx0 区域最小的x
   *@param double my0 区域最小的y
   *@param double mx1 区域最大的x
   *@param double my1 区域最大的x
   *@return void
   *@author: tuyinan
   *@version: 2022-04-xx
   */
  void addExtraBounds(double mx0, double my0, double mx1, double my1);

 protected:
  /**
   *@brief 覆盖方式更新
   *@param costmap_2d::Costmap2D& master_grid 代价地图类
   *@param int min_i 区域最小的x
   *@param int min_j 区域最小的y
   *@param int max_i 区域最大的x
   *@param int max_j 区域最大的y
   *@return void
   *@author: tuyinan
   *@version: 2022-04-xx
   */
  void updateWithTrueOverwrite(costmap_2d::Costmap2D& master_grid, int min_i,
                               int min_j, int max_i, int max_j);

  /**
   *@brief 覆盖方式更新，未知区域不覆盖
   *@param costmap_2d::Costmap2D& master_grid 代价地图类
   *@param int min_i 区域最小的x
   *@param int min_j 区域最小的y
   *@param int max_i 区域最大的x
   *@param int max_j 区域最大的y
   *@return void
   *@author: tuyinan
   *@version: 2022-04-xx
   */
  void updateWithOverwrite(costmap_2d::Costmap2D& master_grid, int min_i,
                           int min_j, int max_i, int max_j);

  /**
   *@brief 最大值更新
   *@param costmap_2d::Costmap2D& master_grid 代价地图类
   *@param int min_i 区域最小的x
   *@param int min_j 区域最小的y
   *@param int max_i 区域最大的x
   *@param int max_j 区域最大的y
   *@return void
   *@author: tuyinan
   *@version: 2022-04-xx
   */
  void updateWithMax(costmap_2d::Costmap2D& master_grid, int min_i, int min_j,
                     int max_i, int max_j);
  /**
   *@brief 值相加更新
   *@param costmap_2d::Costmap2D& master_grid 代价地图类
   *@param int min_i 区域最小的x
   *@param int min_j 区域最小的y
   *@param int max_i 区域最大的x
   *@param int max_j 区域最大的y
   *@return void
   *@author: tuyinan
   *@version: 2022-04-xx
   */
  void updateWithAddition(costmap_2d::Costmap2D& master_grid, int min_i,
                          int min_j, int max_i, int max_j);

  /**
   *@brief 更新最大最小值
   *@param double x x值
   *@param double y y值
   *@param double* min_x 最小x值
   *@param double* min_y 最小y值
   *@param double* max_x 最大x值
   *@param double* max_y 最大y值
   *@return void
   *@author: tuyinan
   *@version: 2022-04-xx
   */
  void touch(double x, double y, double* min_x, double* min_y, double* max_x,
             double* max_y);
  /**
   *@brief 在其他方法updatebounds 中，使得修改的区域只在extra bounds里面
   *@param double* min_x 最小x值
   *@param double* min_y 最小y值
   *@param double* max_x 最大x值
   *@param double* max_y 最大y值
   *@return void
   *@author: tuyinan
   *@version: 2022--xx
   */
  void useExtraBounds(double* min_x, double* min_y, double* max_x,
                      double* max_y);
  /// 是否使用特定区域
  bool has_extra_bounds_;

 private:
  /// 特定区域的*@param double* min_x 最小x值， min_y 最小y值， max_x
  /// 最大x值，max_y 最大y值
  double extra_min_x_, extra_max_x_, extra_min_y_, extra_max_y_;
};

}  // namespace costmap_2d
#endif  // COSTMAP_2D_COSTMAP_LAYER_H_
